package sg.edu.nus.iss.billing.gui;

//Author: Tan Pic Cheng

import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import sg.edu.nus.iss.billing.gui.component.ValidateJTextField;
import sg.edu.nus.iss.billing.localization.MessageKeyManager;
import sg.edu.nus.iss.billing.validation.ValidationRule;

public class CustomerAddressPanel extends JPanel {
	
	String[] labelContent = {MessageKeyManager.getMessage("label.address1"), MessageKeyManager.getMessage("label.address2"), MessageKeyManager.getMessage("label.unit"), MessageKeyManager.getMessage("label.postal"),MessageKeyManager.getMessage("label.country")};
	
	private JLabel lblCustHeader;
	private JLabel lblAdd1;
	private JLabel lblAdd2;
	private JLabel lblUnit;
	private JLabel lblPostal;
	private JLabel lblCountry;
	
	private ValidateJTextField fieldAdd1;
	private ValidateJTextField fieldAdd2;
	private ValidateJTextField fieldUnit;
	private ValidateJTextField fieldPostal;
		
	private int labelHeight = 20;
	private int fieldHeight = 20;
	private int labelWidth = 200;
	private int fieldWidth = 200;
	private int fieldControlX = 150;
	private int lblControlX = 10; 

	public CustomerAddressPanel() {
		// TODO Auto-generated constructor stub
		super();
		init();
	
	}
	private JLabel createLabel(String labelContents, int x, int y){
		
		JLabel labelName = new JLabel(labelContents);
		labelName.setVerticalTextPosition(SwingConstants.BOTTOM);
		labelName.setBounds(x, y, labelWidth, labelHeight);
		add(labelName);
		
		return labelName;		
		
	}
	private ValidateJTextField createTextField(String labelName, String text, int x, int y, ValidationRule ... rules){
		
		ValidateJTextField fieldTxtName = new ValidateJTextField(labelName, rules);
		fieldTxtName.setText(text);
		fieldTxtName.setBounds(x, y, fieldWidth, fieldHeight);
		add(fieldTxtName);	
		
		return fieldTxtName;
		
	}
	public ValidateJTextField getFieldAdd1() {
		
		return fieldAdd1;
		
	}
	public ValidateJTextField getFieldAdd2() {
		
		return fieldAdd2;
		
	}
	public ValidateJTextField getFieldUnit() {
		
		return fieldUnit;
		
	}
	public ValidateJTextField getFieldPostal() {
		
		return fieldPostal;
		
	}
	public void setFieldAdd1(ValidateJTextField fieldAdd1) {
		
		this.fieldAdd1 = fieldAdd1;
		
	}
	public void setFieldAdd2(ValidateJTextField fieldAdd2) {
		
		this.fieldAdd2 = fieldAdd2;
		
	}
	public void setFieldUnit(ValidateJTextField fieldUnit) {
		
		this.fieldUnit = fieldUnit;
		
	}
	public void setFieldPostal(ValidateJTextField fieldPostal) {
		
		this.fieldPostal = fieldPostal;
		
	}
	private void init() {
		// TODO Auto-generated method stub
		setLayout(null);
		setPreferredSize(new Dimension(400,300));
		setBounds( 400, 0, 400, 300);
		
		lblCustHeader = createLabel("Customer Residential Address:", 10, 5);
						
		int controly = 40;
		
		for(int i = 0; i < labelContent.length; i++){
			
			switch(i){
			case 0: lblAdd1 = createLabel(labelContent[i], lblControlX, controly);
					fieldAdd1 = createTextField(labelContent[i], "", fieldControlX, controly, ValidationRule.NOT_NULL);
					break;
			case 1:	lblAdd2 = createLabel(labelContent[i], lblControlX, controly);
					fieldAdd2 = createTextField(labelContent[i], "", fieldControlX, controly, ValidationRule.NOT_NULL);
					break;
			case 2:	lblUnit = createLabel(labelContent[i], lblControlX, controly);
					fieldUnit = createTextField(labelContent[i],"", fieldControlX, controly);
					break;
			case 3:	lblPostal = createLabel(labelContent[i], lblControlX, controly);
					fieldPostal = createTextField(labelContent[i], "", fieldControlX, controly, ValidationRule.NOT_NULL, ValidationRule.LENGTH6, ValidationRule.NUMERIC);
					break;
			case 4: lblCountry = createLabel(labelContent[i], lblControlX, controly);
					createLabel("Singapore", fieldControlX, controly);
					break;
			default:break;
			}//End of Switch
			
			controly = controly + 35;
		}
					
	}

}
